package leetcode.greedy;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class equalString {
    public static void main(String[] args) {
        Scanner scanner =new Scanner(System.in);
        String s1 = scanner.nextLine();
        String s2 = scanner.nextLine();
        System.out.println(isItPossible(s1,s2));
    }
    public static boolean isItPossible(String word1,String word2) {
        HashMap<Character, Integer> hashMap1 = new HashMap<>();//统计第一个字符串不同字符的数量，和每种个数
        for (int i = 0; i < word1.length(); i++) {
            if (hashMap1.containsKey(word1.charAt(i))) {
                hashMap1.put(word1.charAt(i), hashMap1.get(word1.charAt(i)) + 1);
            } else {
                hashMap1.put(word1.charAt(i), 1);
            }
        }
        HashMap<Character, Integer> hashMap2 = new HashMap<>();//统计第二个字符串不同字符的数量，和每种个数
        for (int i = 0; i < word2.length(); i++) {
            if (hashMap2.containsKey(word2.charAt(i))) {
                hashMap2.put(word2.charAt(i), hashMap2.get(word2.charAt(i)) + 1);
            } else {
                hashMap2.put(word2.charAt(i), 1);
            }
        }
        for (int i = 0; i < 26; i++) {
            int length = hashMap1.size();
            int length2 = hashMap2.size();
            if (hashMap1.containsKey((char)('a'+i))){
                if (hashMap1.get((char)('a'+i))==1){
                    length -=1;
                }
                if (!hashMap2.containsKey((char)('a'+i))){
                    length2 +=1;
                }
                for (int j = 0; j < 26; j++) {
                    if (hashMap2.containsKey((char)('a'+j))){
                        if (hashMap2.get((char)('a'+j))==1 && ('a'+i)!=('a'+j) ){
                            length2 = length2-1;
                        }
                        if (!hashMap1.containsKey((char)('a'+j)) || (hashMap1.get((char)('a'+i))==1 && ('a'+i)==('a'+j)) ){
                            length +=1;
                        }
                        if (length == length2){
                            return true;
                        }
                        if (hashMap2.get((char)('a'+j))==1 && ('a'+i)!=('a'+j) ){
                            length2 = length2+1;
                        }
                        if (!hashMap1.containsKey((char)('a'+j)) || (hashMap1.get((char)('a'+i))==1 && ('a'+i)==('a'+j)) ){
                            length -=1;
                        }
                    }
                }
                if (hashMap1.get((char)('a'+i))==1){
                    length +=1;
                }
                if (!hashMap2.containsKey((char)('a'+i))){
                    length2 -=1;
                }
            }
        }
        return false;
    }
}
